<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card class="box-card">
      <div>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-input
              placeholder="请输入内容"
              clearable
              v-model="queryinfo.query"
              @clear="getorderslists"
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click="getorderslists"
              ></el-button>
            </el-input>
          </el-col>
        </el-row>
      </div>
      <!-- 数据表格区域 -->
      <el-table
        :data="orderslists"
        stripe
        border
        style="width: 100%; margin-top: 15px"
      >
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="755px">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="order_pay" label="是否付款">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.pay_status == 0" type="danger"
              >未付款</el-tag
            >
            <el-tag v-else type="success">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="180px">
          <template slot-scope="scope">
            {{ scope.row.create_time | dataFormate }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150px">
          <template>
            <el-button
              type="primary"
              size="small"
              icon="el-icon-edit"
              @click="showEdit"
            ></el-button>
            <el-button
              type="success"
              size="small"
              icon="el-icon-location"
              @click="showaddress"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryinfo.pagenum"
        :page-sizes="[5, 10, 20, 40]"
        :page-size="queryinfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 编辑弹框 -->
    <el-dialog
      title="编辑地址"
      :visible.sync="editVisible"
      width="50%"
      @close="addressDialog"
    >
      <el-form
        :model="addForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="addForm.address1"
            :options="CityData"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editVisible = false">取 消</el-button>
        <el-button type="primary" @click="editVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流地址弹框 -->
    <el-dialog title="物流进度" :visible.sync="addressVisible" width="50%">
      <div class="block">
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in addressactivities"
            :key="index"
            icon="el-icon-map-location"
            type="success"
            size="large"
            :timestamp="activity.time"
          >
            {{ activity.context }}
          </el-timeline-item>
        </el-timeline>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import CityData from './citydata'
export default {
  data() {
    return {
      // 请求数据的参数
      queryinfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
      },
      //  获取到的数据
      orderslists: [],
      // 数据总数
      total: 0,
      // 编辑弹框显示隐藏
      editVisible: false,
      //编辑表单数据
      addForm: {
        address1: [],
        address2: '',
      },
      // 验证规则
      rules: {
        address1: [
          { required: true, message: '请选择省市县乡', trigger: 'blur' },
          {
            min: 3,
            max: 10,
            message: '长度在 3 到 10 个字符',
            trigger: 'blur',
          },
        ],
        address2: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          {
            min: 3,
            max: 10,
            message: '长度在 3 到 10 个字符',
            trigger: 'blur',
          },
        ],
      },
      CityData: CityData,
      // 物流弹框的显示隐藏
      addressVisible: false,
      // 物流信息数据
      addressactivities: [],
    }
  },
  mounted() {
    this.getorderslists()
  },
  methods: {
    // 获取表格数据
    async getorderslists() {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryinfo,
      })
      // console.log(res.data)
      if (res.meta.status !== 200) return this.$message.error('获取失败')
      this.orderslists = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange(newSize) {
      this.queryinfo.pagesize = newSize
      this.getorderslists()
    },
    handleCurrentChange(newPage) {
      this.queryinfo.pagenum = newPage
      this.getorderslists()
    },
    //显示弹框
    showEdit() {
      this.editVisible = true
    },
    // 监听关闭编辑弹框
    addressDialog() {
      this.$refs.ruleForm.resetFields()
    },
    // 显示物流信息
    async showaddress() {
      const { data: res } = await this.$http.get('/kuaidi/' + 1106975712662)
      if (res.meta.status !== 200)
        return this.$message.error('获取物流信息失败！')
      this.addressactivities = res.data
      this.addressVisible = true
    },
  },
}
</script>
<style lang="less" scoped>
</style>